package cn.easybuy.web.backend;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.easybuy.dao.ProductCategoryDao;
import cn.easybuy.dao.impl.ProductCategoryDaoImpl;
import cn.easybuy.entity.Product;
import cn.easybuy.entity.ProductCategory;
import cn.easybuy.service.ProductService;
import cn.easybuy.service.impl.ProductServiceImpl;

public class ProductUpdateServlet extends HttpServlet{

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		ProductCategoryDao pcd=new ProductCategoryDaoImpl();
		String id=request.getParameter("id");
		ProductService ps=new ProductServiceImpl();
		List<Product> products=ps.getProductInfo(Integer.parseInt(id));
		for (Product product : products) {
			request.setAttribute("idl1", product.getCategoryLevel1Id());
			request.setAttribute("idl2", product.getCategoryLevel2Id());
			request.setAttribute("idl3", product.getCategoryLevel3Id());
			request.setAttribute("name",product.getName() );
			request.setAttribute("price", product.getPrice());
			request.setAttribute("stock", product.getStock());
			request.setAttribute("description",product.getDescription() );
			
		}
		//一级菜单
		List<ProductCategory> list1=pcd.getProductCategoriesByType(1);		
		request.setAttribute("list1", list1);
		request.setAttribute("id", Integer.parseInt(id));
		
	
		
		request.getRequestDispatcher("Member_ProductUpdate.jsp").forward(request, response);
	}

}
